# -*- coding: utf-8 -*-

from w.blocks.block import BaseBlock as Block
from w.blocks.containers.checkbox import CheckBox as CheckBoxContainer

class CheckBox(CheckBoxContainer, Block):
    scriptFiles = ['w/blocks/string_field.js',
                   'w/blocks/checkbox.js']

    def __init__(self, content=None, disableDefaultValue=False, focusedClass=None, *argv, **kwargv):
        CheckBoxContainer.__init__(self, content, *argv, **kwargv)
        Block.__init__(self, *argv, **kwargv)

        self.tag.html.id = 'dom%s'%self.blockID
        self.disableDefaultValue = disableDefaultValue
        self.focusedClass = focusedClass

        if not self.disableDefaultValue:
            self.tag.html.onFocus=self.js.onFocusIn()
            self.tag.html.onBlur=self.js.onFocusOut()

    def jsCode(self):
        if self.disableDefaultValue:
            return Block.jsCode(self)
        return '%s\n%s\n%s'%(Block.jsCode(self),
                            self.js.defaultValue << self[0],
                            self.js.changeClassOnFocusTo << self.focusedClass)

    def make(self, content=[]):
        return Block.make(self, CheckBoxContainer.make(self, content))
